n = int(input())
ws = [tuple(map(int, input().split())) for i in range(n)]

ws = sorted(ws, key=lambda x: x[1]+x[0])
res = -2**31-1
print(res)
sum = 0
for i in range(n):
    res = max(sum - ws[i][1], res)
    sum += ws[i][0]
print(res)


